package com.duobaoyu.dby.supply.admin.controller.order;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.duobaoyu.dby.channel.adapter.enums.OperationTypeEnum;
import com.duobaoyu.dby.common.core.util.R;
import com.duobaoyu.dby.supply.admin.annotation.SupplySysLog;
import com.duobaoyu.dby.supply.admin.service.AdminOrderBizService;
import com.duobaoyu.dby.supply.common.biz.dto.order.OperateRemarkDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderCancelDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderPageDTO;
import com.duobaoyu.dby.supply.common.biz.dto.order.OrderStatusUpdateDTO;
import com.duobaoyu.dby.supply.common.biz.vo.order.OrderBlanketDetailVO;
import com.duobaoyu.dby.supply.common.biz.vo.order.OrderPageVO;
import com.duobaoyu.dby.supply.common.biz.vo.order.OrderSubDetailVO;
import com.duobaoyu.dby.supply.core.task.bean.exporttask.ExportParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * 订单管理
 *
 * @author jz
 * @version 1.0
 * @date 2022/6/2 09:48
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/admin/order")
@Api(value = "order", tags = "订单")
public class OrderController {
	private final AdminOrderBizService adminOrderBizService;

	/**
	 * 分页获取订单列表
	 **/
	@GetMapping("/pageList")
	@ApiOperation(value = "订单列表", notes = "订单列表")
	@SupplySysLog(value = "订单列表",operationType = OperationTypeEnum.SELECT)
	public R<Page<OrderPageVO>> pageOrderList(@Valid OrderPageDTO orderPage) {
		return R.ok(adminOrderBizService.pageOrderList(orderPage));
	}

	/**
	 * 运营备注
	 * @return R<Boolean>
	 */
	@PostMapping("/operate/remark")
	@ApiOperation(value = "运营备注", notes = "运营备注")
	@SupplySysLog(value = "运营备注",operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> saveOperateRemark(@Valid @RequestBody OperateRemarkDTO operateRemark){
		return R.ok(adminOrderBizService.saveOperateRemark(operateRemark));
	}

	/**
	 * 订单列表导出
	 *
	 * @param param 入参
	 * @return
	 */
	@PostMapping("/export")
	@ApiOperation(value = "订单列表导出", notes = "订单列表导出")
	@SupplySysLog(value = "订单列表导出",operationType = OperationTypeEnum.SELECT)
	public R<Boolean> exportExcel(@RequestBody ExportParam<OrderPageDTO> param) {
		return R.ok(adminOrderBizService.export(param));
	}

	/**
	 * 子单详情
	 * @param orderSn 供应链订单号
	 */
	@GetMapping("/sub/detail/{orderSn}")
	@ApiOperation(value = "子单详情", notes = "子单详情")
	@SupplySysLog(value = "子单详情",operationType = OperationTypeEnum.SELECT)
	public R<OrderSubDetailVO> orderSubDetail(@PathVariable String orderSn) {
		return R.ok(adminOrderBizService.orderSubDetail(orderSn));
	}

	/**
	 * 总单详情
	 * @param supplyTradeSn 供应链交易单号
	 */
	@GetMapping("/blanket/detail/{supplyTradeSn}")
	@ApiOperation(value = "总单详情", notes = "总单详情")
	@SupplySysLog(value = "总单详情",operationType = OperationTypeEnum.SELECT)
	public R<OrderBlanketDetailVO> orderBlanketDetail(@PathVariable String supplyTradeSn) {
		return R.ok(adminOrderBizService.orderBlanketDetail(supplyTradeSn));
	}

	/**
	 * 取消订单
	 * @return R<Boolean>
	 */
	@PostMapping("/cancel")
	@ApiOperation(value = "取消订单", notes = "取消订单")
	@SupplySysLog(value = "取消订单", operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> cancelOrder(@RequestBody @Valid OrderCancelDTO orderCancel){
		return R.ok(adminOrderBizService.cancelOrder(orderCancel));
	}

	/**
	 * 修改订单状态
	 */
	@PostMapping("/updateStatus")
	@ApiOperation(value = "修改订单状态", notes = "修改订单状态")
	@SupplySysLog(value = "修改订单状态", operationType = OperationTypeEnum.UPDATE)
	public R<Boolean> modifyOrderStatus(@RequestBody @Valid OrderStatusUpdateDTO orderStatusUpdateDTO){
		return R.ok(adminOrderBizService.modifyOrderStatus(orderStatusUpdateDTO));
	}
}
